package training.minggu5.maven;



import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import training.minggu5.maven.domain.Barang;
import training.minggu5.maven.domain.PenjualanDetail;
import training.minggu5.maven.domain.PenjualanHeader;
import training.minggu5.maven.service.BarangService;
import training.minggu5.maven.service.PenjualanDetailService;
import training.minggu5.maven.service.PenjualanHeaderService;


public class Main {
/*
    private static ApplicationContext apcon;
    private static BarangService barvice;
    private static PenjualanHeaderService headvice;
    private static PenjualanDetailService deathfish;

    public static void main(String[] args) {

        String file = "classpath:/training/minggu5/maven/service/impl/applicationContext.xml";
        apcon = new ClassPathXmlApplicationContext(file);
        barvice = (BarangService) apcon.getBean("barangService");
        headvice = (PenjualanHeaderService) apcon.getBean("penjualanHeaderService");
        deathfish = (PenjualanDetailService) apcon.getBean("penjualanDetailService");

        
        Barang bar = new Barang();
        bar.setKodeBarang("70KA4");
        bar.setNamaBarang("toka4");
        bar.setUnitPrice(new BigDecimal(20000));
        barvice.saveBarang(bar);
        

        List<Barang> lisbar = barvice.findAllBarang();
        System.out.println("\nkode\tnama\tunit_price");
        for(Barang a : lisbar){
            System.out.println(a.getKodeBarang()+"\t"+a.getNamaBarang()+"\t"+a.getUnitPrice());
        }
        System.out.println();

        PenjualanHeader penh = new PenjualanHeader();
        PenjualanDetail pend = new PenjualanDetail();
        PenjualanDetail pend2 = new PenjualanDetail();

        Barang satu = barvice.findBarangByKode("70KA1");
        Barang dua = barvice.findBarangByKode("70KA2");

        //set detail penjualan #1
        pend.setBarang(satu);
        pend.setJumlah(3);
        pend.setHarga(satu.getUnitPrice().multiply(new BigDecimal(pend.getJumlah())));
        pend.setDet_Penjualan_header(penh);
        
        //set detail penjualan #2
        pend2.setBarang(dua);
        pend2.setJumlah(2);
        pend2.setHarga(dua.getUnitPrice().multiply(new BigDecimal(pend2.getJumlah())));
        pend2.setDet_Penjualan_header(penh);
        
        List<PenjualanDetail> listdetail = new ArrayList<PenjualanDetail>();
        listdetail.add(pend);
        listdetail.add(pend2);

        //set penjualan header
        penh.setNama_konsumen("nama konsumen nih");
        penh.setTanggal(new Date());
        penh.setList_penjualan_detail(listdetail);

        headvice.savePenjualanHeader(penh);

        List<PenjualanHeader> lishead = headvice.findAllPenjualanHeader();
        for(PenjualanHeader a : lishead){
            System.out.println(a.getNoFaktur()+"\t"+a.getNama_konsumen()+"\t"+a.getTanggal());
        }

        List<PenjualanDetail> lisdet = deathfish.findAllPenjualanDetail();
        for(PenjualanDetail a : lisdet){
            System.out.println(a.getId_penjualan_detail()+"\t"+a.getBarang().getNamaBarang()+"\t"+a.getHarga()+"\t"+a.getDet_Penjualan_header().getNoFaktur());
        }

    }*/
}
